<template>
    <view>
		<cu-custom bgColor="bg-gradual-blue">
			<block slot="content">个人中心</block>
		</cu-custom>
        <view class="margin-top">
            <button v-if="!!hasLogin" type="primary" class="primary" @tap="bindLogin">登录</button>
            <button v-if="!hasLogin" type="default" @tap="bindLogout">退出登录</button>
        </view>
    </view>
</template>

<script>
    import {
        mapState,
        mapMutations
    } from 'vuex'

    export default {
		data() {
			return {
				hasLogin: false
			}
		},
		onLoad() {
			this.hasLogin = uni.getStorageSync('LOGIN_KEY')
		},
        computed: {
            ...mapState(['forcedLogin'])
        },
        methods: {
            ...mapMutations(['logout']),
            bindLogin() {
                uni.navigateTo({
                    url: '../login/login',
                });
            },
            bindLogout() {
                this.logout();
                /**
                 * 如果需要强制登录跳转回登录页面
                 */
				alert(3)
                if (this.forcedLogin) {
					alert(44)
                    uni.reLaunch({
                        url: '../login/login',
                    });
                }
            }
        }
    }
</script>

<style>

</style>
